Method of training a logistic regression classifier with a resistive random access memory

ABSTRACT

A method for training a logistic regression classifier on a dataset by using a resistive RAM as hardware accelerator, each row of the resistive RAM including cells which can be programmed in a first resistance state or a second resistance state. The probability of a data element belonging to a class is modelled by a logistic function applied to a score of the element, where is a parameter vector of the model. The logistic regression classifier is trained by populating the resistive RAM with samples of a model parameter vector which are obtained by MCMC sampling. Once populated, the resistive RAM can be used for classifying new data.

FIELD OF THE INVENTION

The present invention concerns the field of machine learning and more specifically the use of Markov Chain Monte Carlo (MCMC) sampling for machine learning. The invention also relates to the field of resistive Random Access Memories (RRAMs).

BACKGROUND OF THE INVENTION

Classification is a common problem within machine learning. Basically, classifying amounts to predicting a qualitative response for an observation i.e. assigning the observation to a category or a class. Many classification techniques are available to predict a qualitative response. A very popular supervised classification method is logistic regression.

Consider an example of dataset as illustrated in FIG. 1. Each element of the dataset can be described by two attributes (or features) x₁, x₂ and has a binary response t=10,11. In other words, each element can be classified as belonging to a first class, t=0, (points plotted as a circle) or as belonging to a second class, t=0 (points plotted as a square).

The data elements of the dataset can be represented by vectors x_(n), the size of which being the number M of attributes (here M=2). These vectors can be stacked in a matrix X=(x₁ ^(T), x₂ ^(T), . . . , x_(N) ^(T))^(T) where N is the number of elements in the dataset, thereby representing the whole dataset. Similarly, the responses of the elements of the dataset can be stacked in a vector t=(t₁, t₂, . . . , t_(N))^(T).

We look for a linear model which would allow us to classify the data elements of the dataset according to their known responses and predict the class of a new observation x_(new). More specifically, we assume that for any data element x_(n) of the dataset the probability that it belongs to the first class (T_(n)=0) decreases with the dot product w^(T)x_(n) where w is a vector, hereinafter referred to as parameter vector capturing the parameters of the model. Conversely, we assume that the probability that data element x_(n) belongs to the second class (T_(n)=1) increases with the dot product. A simple way to convert the dot product into a probability value is to squash the dot product into the range [0,1] with a sigmoid function (a.k.a. standard logistic function), according to the logit model:

$\begin{matrix} {{P\left( {T_{n} = \left. 1 \middle| x_{n} \right.} \right)} = \frac{1}{1 + {\exp \left( {{- w^{T}}x_{n}} \right)}}} & \left( {1\text{-}1} \right) \end{matrix}$

and therefore:

$\begin{matrix} {{P\left( {T_{n} = \left. 0 \middle| x_{n} \right.} \right)} = {{1 - {P\left( {T_{n} = \left. 1 \middle| x_{n} \right.} \right)}} = \frac{\exp \left( {{- w^{T}}x_{n}} \right)}{1 + {\exp \left( {{- w^{T}}x_{n}} \right)}}}} & \left( {1\text{-}2} \right) \end{matrix}$

Following a Bayesian approach, we now consider the parameter vector as a random vector and are interested in finding the posterior probability density (also called posterior density or, simply, posterior) knowing the dataset elements and their respective classes, that is p(w|t, X). The posterior can be obtained from the prior probability density, p(w), (also called prior density or, simply, prior), the likelihood p(t|X, w) and the marginal likelihood, p(t|X), according to Bayes' rule:

$\begin{matrix} {{p\left( {\left. w \middle| t \right.,X} \right)} = \frac{{p\left( {\left. t \middle| X \right.,w} \right)}{p(w)}}{p\left( t \middle| x \right)}} & (2) \end{matrix}$

where the marginal likelihood is obtained by p(t|X)=∫p(t|X, w)p(w)dw.

In the following, the posterior p(w|t, X) will simply be denoted π(w) and the likelihood of parameter vector w, p(t|X, w), will be denoted

(w). Since p(t|X) is a constant depending only upon the dataset, the posterior is proportional to the product of the likelihood with the prior:

π(w)=Z

(w)·p(w)   (3)

where Z is a constant.

It should be noted that the terms posterior and prior always refer to the available observations (the dataset X) and their respective responses (t).

Assuming that the elements of t are conditionally independent, the likelihood

(w) can be expressed as follows:

$\begin{matrix} {{(w)} = {{p\left( {\left. t \middle| X \right.,w} \right)} = {{\prod\limits_{n = 1}^{N}{p\left( {\left. t_{n} \middle| x_{n} \right.,w} \right)}} = {\prod\limits_{n = 1}^{N}{\left( {p\left( {{T_{n} = \left. 1 \middle| x_{n} \right.},w} \right)} \right)^{t_{n}}\left( {p\left( {{T_{n} = \left. 0 \middle| x_{n} \right.},w} \right)} \right)^{1 - t_{n}}}}}}} & (4) \end{matrix}$

and therefore, substituting expressions (1-1) and (1-2) into (4):

$\begin{matrix} {{(w)} = {\prod\limits_{n = 1}^{N}{\left( \frac{1}{1 + {\exp \left( {{- w^{T}}x_{n}} \right)}} \right)^{t_{n}}\left( \frac{\exp \left( {{- w^{T}}x_{n}} \right)}{1 + {\exp \left( {{- w^{T}}x_{n}} \right)}} \right)^{1 - t_{n}}}}} & (5) \end{matrix}$

Even assuming a known distribution e.g. a Gaussian distribution for the prior π(w), it is generally impossible to compute the denominator Z⁻¹ of (2) because the integration of the likelihood p(t|X, w) for obtaining the marginal likelihood p(t|X ) is not analytically tractable.

Several options are available at this stage. According to a first option, one may look for the parameter vector, ŵ_(MAP) (where MAP stands for Maximum A Posteriori) achieving the maximum value of the posterior, π(w) and predict the class of a new observation according to (1-1) and (1-2) with the MAP parameter vector, ŵ_(MAP). According to a second option, referred to as Laplace approximation, one may try to approximate the posterior around its maximum value by a gaussian distribution. A third option, which better captures the distribution of the parameter vector is to sample the posterior π(w) knowing the likelihood

(w) and the prior p(w) and availing of the proportionality relationship (3). Sampling means drawing samples of the parameter vector w according to the posterior π(w). Once Ns samples of the posterior have been obtained, w_(s), s=1, . . . , Ns , namely once we have got Ns models we can predict the class of a new observation x_(new) (unseen data point) by calculating the average:

$\begin{matrix} {{P\left( {T_{n} = \left. 1 \middle| x_{new} \right.} \right)} = {\frac{1}{NS}{\sum\limits_{s = 1}^{Ns}\frac{1}{1 + {\exp \left( {{- w_{s}^{T}}x_{new}} \right)}}}}} & \left( {6\text{-}1} \right) \end{matrix}$

and therefore:

$\begin{matrix} {{P\left( {T_{n} = \left. 0 \middle| x_{new} \right.} \right)} = {{1 - {P\left( {T_{n} = \left. 1 \middle| x_{new} \right.} \right)}} = {\frac{1}{Ns}{\sum\limits_{s = 1}^{Ns}\frac{\exp \left( {{- w_{s}^{T}}x_{new}} \right)}{1 + {\exp \left( {{- w_{s}^{T}}x_{new}} \right)}}}}}} & \left( {6 - 2} \right) \end{matrix}$

Each instance of w_(s) capturing the model parameters is associated with a linear decision boundary in the space of attributes as shown in FIG. 2. More generally, each sample w_(s)defines a decision boundary is the form of a hyperplane in the space of attributes.

It follows from expression (6-1) and (6-2) that we can train a logistic regression classifier on the data set X with known labels t provided we are able to sample the posterior π(w).

The sampling of π(w) can be achieved by a so-called MCMC (Markov Chain Monte Carlo) technique allowing to explore the parameter space according to a Markov stochastic process. A popular sampling algorithm using this technique is the Metropolis-Hastings algorithm which is outlined further below. A detailed presentation of the Metropolis-Hastings algorithm and its application to machine learning can be found for instance in the book by Simon Rogers and Mark Girolami entitled “First course in Machine Learning”, Chapter IV, second edition, Chapman & Hall/CRC Press, 2017, or in the article of C. Andrieu et al. entitled “An introduction to MCMC for machine learning” published in Machine Learning, vol. 5, pages 5-43, 2003.

A flowchart of the Metropolis-Hastings algorithm is illustrated in FIG. 3.

It assumes that a conditional probability density for moving from a parameter vector to a next one is defined beforehand.

The algorithm starts at step 310 with an arbitrary parameter vector w₀, and by initialising an iteration counter s=0.

At step 320, the iteration counter is incremented by one, that is s=s+1.

At step 330, a new candidate parameter vector, {tilde over (w)}_(s), is generated by using the conditional probability density p({tilde over (w)}_(s)|w_(s−1)) mentioned above. Without prejudice to generality, this conditional probability density can be chosen Gaussian, i.e. p({tilde over (w)}_(s)|w_(s−1))□N(w_(s−1), Σ) where Σ is a predetermined covariance matrix. Σ is chosen diagonal and its eigenvalues are chosen commensurate with the parameter space to explore. It should be noted that the conditional probability density is simply here to define a random walk through the parameter space and is not related to the posterior π(w).

FIG. 4 illustrates an example of random walk in the model space performed by the Metropolis-Hastings algorithm. The average size of a move from one sample to the next is given by the eigenvalues of the covariance matrix.

Returning to the flowchart of FIG. 3, step 340 calculates an acceptance ratio, r, defined as the ratio of the posterior density at the candidate sample {tilde over (w)}_(s) to that at the previous sample w_(s−1), divided by the ratio of the proposed densities, namely:

$\begin{matrix} {r = {{\frac{\pi \left( {\overset{\sim}{w}}_{s} \right)}{\pi \left( w_{s - 1} \right)} \cdot \frac{p\left( {w_{s - 1}{\overset{\sim}{w}}_{s}} \right)}{p\left( {{\overset{\sim}{w}}_{s}w_{s - 1}} \right)}} = \frac{\pi \left( {\overset{\sim}{w}}_{s} \right)}{\pi \left( w_{s - 1} \right)}}} & (7) \end{matrix}$

since the Gaussian distribution is symmetrical. The acceptance ratio r appraises the suitability of the candidate vector {tilde over (w)}_(s) to better classify the data of the dataset than vector w_(s−1) output by the previous iteration.

Although the posteriors cannot be calculated due to the presence of the constant Z , their ratio can be easily obtained from expression (3) as the product of the ratio of the priors with the ratio of likelihoods:

$\begin{matrix} {r = {\frac{\pi \left( {\overset{\sim}{w}}_{s} \right)}{\pi \left( {\overset{\sim}{w}}_{s - 1} \right)} = {\frac{\left( {\overset{\sim}{w}}_{s} \right)}{\left( w_{s - 1} \right)} \cdot \frac{p\left( {\overset{\sim}{w}}_{s} \right)}{p\left( w_{s - 1} \right)}}}} & (8) \end{matrix}$

in which we will assume that the priors are all Gaussian i.e. p({tilde over (w)}_(s))□N(0, σI_(M)) and p(w_(s−1))□N(0, σI_(M)), where I_(M) is the identity matrix of size M×M, M being the size of the data elements, that is the number of attributes.

It is checked at step 350 whether the acceptance ratio is greater than or equal to 1. In the affirmative, the algorithm jumps to step 353 where the candidate vector is accepted that is w_(s)={tilde over (w)}_(s). In the negative, the algorithm proceeds further with step 360 where a sample value, u, of a random variable U having a uniform probability density on the interval [0,1] is drawn.

It is then checked at step 370 whether the sample value, u, is lower than or equal than the acceptance ratio, r. In the affirmative, the algorithm jumps to step 353 where the candidate vector is accepted, that is w_(s)={tilde over (w)}_(s). However, in the negative, the candidate vector is rejected at step 357 and the parameter vector output by the iteration s is chosen equal to the one output by previous iteration, that is w_(s)=w_(s−1).

In other words, if posterior density at {tilde over (w)}_(s) is higher that the posterior density at w_(s−1), the candidate vector is systematically retained whereas it is only conditionally retained otherwise. Hence, it should be understood that due to the rejection mechanism, several consecutive samples of the sequence w_(s), s=1, . . . , Ns may be identical.

After having being updated by the candidate vector (step 353) or not (step 357), the algorithm goes back to step 320 for a new iteration.

Since, u≤1, it is important to note that step 350 can be skipped. It suffices then to compare the acceptance ratio, r, with u in 370, the parameter vector being updated with {tilde over (w)}_(s) if u≤r and being kept equal identical to the previous parameter vector w_(s−1) otherwise.

The algorithm stops when a predetermined stopping criterion (not represented) is met, e.g. when a predetermined number N_(s) of samples have been obtained.

The Metropolis-Hastings algorithm can be run on a traditional computer for training a logistic regression classifier. However, when the dataset is large or when the size (N_(s)) of the model is large, the algorithm requires a large size memory and powerful computer resources.

An object of the present invention is to propose a method for training a logistic regression classifier which can be carried out very efficiently on a hardware accelerator having very simple architecture.

BRIEF DESCRIPTION OF THE INVENTION

The present invention is defined by the appended independent claims. Various preferred embodiments are defined in the dependent claims.

BRIEF DESCRIPTION OF THE DRAWINGS

The present invention will be better understood from the description of the following embodiments, by way of illustration and in no way limitative thereto:

FIG. 1 schematically illustrates an example of a dataset defined by two features following a binary response model;

FIG. 2 schematically illustrates decision boundaries corresponding to instances of the model parameters for separating the two classes of response in FIG. 1;

FIG. 3 schematically illustrates the flow chart of the Metropolis-Hastings algorithm for sampling the model parameters;

FIG. 4 shows an example of random walk in the model space performed by the Metropolis-Hastings algorithm;

FIG. 5 shows examples of a probability density function of the resistance value of a cell in a low resistance state as well as examples of a probability density function of the resistance value of a cell in a high resistance state;

FIG. 6 shows the relationship between the SET programming current and the median low resistance value of a cell in an LRS state;

FIG. 7 shows the relationship between the RESET programming voltage and the median high resistance value of a cell in an HRS state;

FIG. 8 shows the structure of a RRAM which can be used for a training method according to a first embodiment of the invention;

FIG. 9 schematically illustrates the flowchart of a method for training a logistic regression classifier on a dataset by using the RRAM of FIG. 8, according to the first embodiment of the invention;

FIG. 10 shows a method for classifying new data with a RRAM based logistic regression classifier after it has been trained by a training method according to the first embodiment of the invention;

FIG. 11 shows the structure of a RRAM which can be used for a training method according to a second embodiment of the invention;

FIG. 12 schematically illustrates the programming of a RRAM according to a binary regime.

DETAILED DISCLOSURE OF PARTICULAR EMBODIMENTS

The idea at the basis of the present invention is to use a resistive switching RAM also simply called resistive memory (RRAM) for implementing the training of a logistic regression classifier according to the Metropolis-Hastings algorithm. More specifically, the invention makes use of the cycle to cycle (C2C) variability programmed resistances in a RRAM, namely of the low-resistance after a SET operation or of the high-resistance after a RESET operation, in order to generate successive parameter vectors of the model.

We recall that a resistive switching RAM consists of non-volatile random access memory cells, each cell comprising a resistor made of dielectric which can be programmed either in a low resistance state (LRS) with a so-called SET operation or in a high resistance state (HRS) with a so-called RESET operation. During a SET operation, a strong electric field is applied to the cell, while limiting the current to a programming current value. This operation forms a conductive filament through the dielectric and brings the resistor to a low resistance value, R_(LO) which depends upon the programming current value.

Conversely, during a RESET operation, a programming voltage is applied to the cell with the same or opposite polarity than the one used for electroforming. This voltage breaks the filament and the resistor returns therefore to a high resistance value, R_(HI) which depends upon the programming voltage value.

A detailed description of RRAM can be found in the article by R. Carboni and D. Ielmini, entitled “Stochastic memory devices for security and computing”, published in Adv. Electron. Mat., 2019, 5, 1900198, pages 1-27.

Once a cell has been programmed by a SET or a RESET operation, the resistance value (R_(LO) or R_(HI)) is stable in time until the next operation is performed. However, the low resistance value varies from one SET operation to the next, even if the programming current is kept constant. More specifically, for a given programming current, the low resistance R_(LO) can be considered as a random variable which exhibits a normal distribution over SET operations (cycle to cycle variability). Expressed otherwise, each time a SET operation is applied to the memory cell, the obtained resistance value is sampled from this normal distribution.

Similarly, the high resistance value varies from one RESET operation to the next, even if the programming voltage is kept constant. More specifically, for a given programming voltage, high resistance R_(HI) can be considered as a random variable which follows a log-normal distribution over the RESET operations (cycle to cycle variability). In other words, each time a RESET operation is applied to the memory cell, the obtained resistance value is sampled from this log-normal distribution.

FIG. 5 shows, on its left side, examples of probability density function of R_(LO) for a cell in a low resistance state. The three examples shown correspond to three different RRAM cells. It also shows, on its right side, examples of probability density function of R_(HI) for a cell in a high resistance state HRS. The three examples shown correspond to the same three RRAM cells. The probability density function has been obtained by cycling 100 times each of the cells. The x-axis being represented in logarithm scale and the shape of R_(HI) distribution being Gaussian, this confirms that R_(HI) follows a log-normal distribution.

The median value of the R_(LO) distribution (or, equivalently, the mean value since the distribution is normal) depends on the programming current value during the SET operation as illustrated in FIG. 6. The x-axis indicates the programming current (in μA) according to a logarithmic scale whereas the y-axis indicates the median value R_(LO) ^(median) (in Ω) according to a logarithmic scale. This dependency being linear in log scale, it follows that the median value of the low resistance follows a power law of the type R_(LO) ^(median)=α(I_(SET))^(−γ) where α and γ are positive coefficients.

Furthermore, the median value of the R_(HI) distribution depends upon the programming voltage value during the RESET operation, as illustrated in FIG. 7. The x-axis indicates the programming voltage (in V) according to a linear scale whereas the y-axis indicates the median value, R_(HI) ^(median) (in Ω) according to a logarithmic scale. This dependency being linear in semi-log scale, it follows that the median value of the high resistance follows an exponential law of the type R_(HI) ^(median)=b exp(λV_(RESET)) where b and λ are positive coefficients.

According to a first embodiment of the invention, the method for training a logistic regression classifier uses a resistive RAM structure as shown in FIG. 8.

The resistive RAM is comprised of word lines which are addressed by word select signals row[0], row[1], . . . , row[P]. Each word line is comprised of M cells where M stands for the number of attributes, each word line being intended to store a sample a parameter word of the model. Furthermore, each word line is associated with a counter of occurrences, the function of which will be described further below.

The cells of a column, m=1, . . . , M, can be fed with a data control signal col[m]. Each cell comprises a FET transistor, the gate of which is controlled by a word select signal and the source of which is connected to a data control signal through a resistor, R_(p,m). The drains of the FETs of a word line, p=1, . . . , P, are all connected to the same output line, out[p].

During a write operation into a cell located at the intersection of row p and column m, word select signal row[p] is applied and a programming voltage is applied to col[m]. The programming can occur during a SET operation or a RESET operation as mentioned above.

During a read operation of a cell located at the intersection of row p and column m, a word select signal is applied at row[p] and a data control signal is applied at col[m]. Assuming that a voltage x_(m), is applied to col[m], the output line output[p] will output a current x_(m)/R_(p,m)=g_(p,m)x_(m), where g_(p,m), is the conductance of the resistive RAM cell. If the RAM cell was programmed to store a value (of conductance) w_(p,m), the output current would be w_(p,m)·x_(m). Hence, if all the cells of a line are read simultaneously, the output current of line output[p] will be the value of the dot product w_(p) ^(T)x, where x=(x₁, . . . , x_(M))^(T) and w_(p) is the parameter vector stored at line p.

The resistive RAM of FIG. 8 can be used as hardware accelerator for training a logistic regression classifier on a dataset as explained in the flowchart of FIG. 9.

We adopt here the same notations as in the introductory part of the application. Each element of the training dataset is represented by M attributes which can be stacked in a vector x of size M. Each element of the training dataset is labelled with a binary target t indicating whether the element in question belongs to a first class or to a second class.

The probability of an element x belonging to a class is modelled by a logistic function applied to a score w^(T)x where w is a parameter vector of size M. More specifically, the probability of element x belonging to the first class is given by:

$\begin{matrix} {{P\left( {T_{n} = \left. 1 \middle| ϰ \right.} \right)} = {\frac{1}{Ns}{\sum\limits_{s = 1}^{Ns}\frac{1}{1 + {\exp \left( {{- w_{s}^{T}}x} \right)}}}}} & \left( {9 - 1} \right) \end{matrix}$

whereas the probability of this element belonging to the second class is given by:

$\begin{matrix} {{P\left( {T_{n} = \left. 0 \middle| x \right.} \right)} = {\frac{1}{Ns}{\sum\limits_{s = 1}^{Ns}\frac{\exp \left( {{- w_{s}^{T}}x} \right)}{1 + {\exp \left( {{- w_{s}^{T}}x} \right)}}}}} & \left( {9 - 2} \right) \end{matrix}$

where the parameter vectors w_(s), s=1, . . . , Ns are obtained by MCMC sampling the posterior π(w), that is knowing the elements of the dataset X and their respective labels.

At step 900, the RRAM is initialised by programming all the cells in either the first resistance state (LRS), according to a first variant or the second resistance state (HRS), according to a second variant that is by performing a SET operation (first variant) or a RESET operation (second variant) on all the cells of the RRAM. Preferably, the cells are programmed in the first resistance state for reasons that will become more apparent below.

At step 910, the first row of the RAM is read, that is the data {tilde over (w)}_(0,1), . . . , {tilde over (w)}_(0,M) forming a first initial parameter vector {tilde over (w)}₀. The counter of iterations s is initialized, s=0. The counters of occurrences associated with the different rows are reset to zero.

The training method then enters an iterative loop, where s stands for the current iteration, w_(s−1) is the current parameter vector which has already been stored in the RRAM at the previous iteration and {tilde over (w)}_(s) is a candidate parameter vector at iteration s

At step 920, the counter of iterations is incremented, s=s+1.

At step 930, a candidate parameter vector, {tilde over (w)}_(s), is generated from the current parameter vector, w_(s−1), by reading the cells of the current row and programming the cells of the next row with a SET operation (1^(st) variant) or with a RESET operation (2^(nd) variant). More specifically a current or voltage is read from the cell of current row j and applied as a voltage to the cell of the next row of the same column. By so doing, a candidate vector, {tilde over (w)}_(s), is generated with conditional probability p({tilde over (w)}_(s)|w_(s−1))according to a normal distribution law (1^(st) variant), and stored temporarily at row j+1. As to the second variant, the current or voltage read from the cell current row j is generated with a conditional probability which follows a log-normal law. Preferably, the read current or voltage is applied to an exponential amplifying circuit (for example an operational amplifier having an exponential characteristic element, such as a diode or biased FET on its non-inverting input) before being applied to the cell of the next row and same column. The exponential amplifying circuit projects the log-normal distribution into a normal distribution.

It follows from this step that the resistances of the cells of the next row are derived from the resistances of the current row according to a Markovian process.

At step 940, the current parameter vector, w_(s−1), and the candidate parameter, {tilde over (w)}_(s), respectively stored at the current row and at the next row are read from the RRAM. The priors p({tilde over (w)}_(s)) and p(w_(s−1)) are calculated by a processor (not shown) from a predetermined gaussian law which may have been obtained during a calibration phase. Preferably, these values are calculated under a logarithm form, i.e. log(p({tilde over (w)}_(s))) and log(p({tilde over (w)}_(s−1))).

At step 950, the vectors x_(n), n=1, . . . , N of the dataset X are applied in turn to the set of columns of the RRAM. The output lines output[j] and output[j+1] respectively output the dot products {tilde over (w)}_(s) ^(T)·x_(n) and w_(s−1) ^(T)·x_(n) n=1, . . . , N , which are supplied to the processor.

At step 960, the processor computes the likelihoods

({tilde over (w)}_(s)) and

(w_(s−1)) from expression (5):

$\begin{matrix} {\mspace{79mu} {{\left( {\overset{\sim}{w}}_{s} \right)} = {\prod\limits_{n = 1}^{N}{\left( \frac{1}{1 + {\exp \left( {{- {\overset{\sim}{w}}_{s}}x_{n}} \right)}} \right)^{t_{n}}\left( \frac{\exp \left( {{- {\overset{\sim}{w}}_{s}^{T}}x_{n}} \right)}{1 + {\exp \left( {{- {\overset{\sim}{w}}_{s}^{T}}x_{n}} \right)}} \right)^{1 - t_{n}}}}}} & \left( {10 - 1} \right) \\ {{\left( w_{s - 1} \right)} = {\prod\limits_{n = 1}^{N}{\left( \frac{1}{1 + {\exp \left( {{- w_{s - 1}}x_{n}} \right)}} \right)^{t_{n}}\left( \frac{\exp \left( {{- w_{s - 1}^{T}}x_{n}} \right)}{1 + {\exp \left( {{- w_{s - 1}^{T}}x_{n}} \right)}} \right)^{1 - t_{n}}}}} & \left( {10 - 2} \right) \end{matrix}$

It is noted that for each term of product (10-1) or (10-2) only one of the two ratios has to be computed (namely the one corresponding to t_(n)=1).

Preferably, the log-likelihoods log(

({tilde over (w)}_(s))) and log(

(w_(s−1))) are calculated instead as a sum of terms, only those being weighted by t_(n)=1 needing to be computed.

The processor then computes the product of the ratio of the likelihoods

$\frac{\left( {\overset{\sim}{w}}_{s} \right)}{\left( w_{s - 1} \right)}$

with the ratio of the priors

$\frac{p\left( {\overset{\sim}{w}}_{s} \right)}{p\left( w_{s - 1} \right)}$

to obtain the acceptance ratio according to expression (8).

Preferably, the acceptance ratio can be computed under its logarithm form, log(r) as the sum of difference of log-likelihoods and difference of log of priors.

At step 970, a random value u is sampled from a random variable U exhibiting a uniform probability density law over range [0,1]. The random value can be generated by the processor. Alternatively, it can be generated by a dedicated row of the RRAM, for example row[P] as shown in FIG. 8. In order to obtain a uniform distribution, a voltage close to the threshold SET voltage is applied as data control signal to the columns col[m] m=1, . . . , M. In such instance, each cell has a probability ½ to be in the LRS state and a probability ½ to be in the HRS state. Upon reading the word stored at row[P], the output line output[P] supplies current is supplied which is uniformly generated between 0 and a predetermined value I_(max), from which the random value u of uniform law over range [0,1] can be derived.

At step 980, the acceptance ratio r is compared with the random value u. In practice, the comparison can be performed between the logarithmic values log(r) and log(u).

If r≥u, the candidate parameter vector w{tilde over (w)}_(s) is retained as the new current vector at step 983, that is w_(s)=w{tilde over (w)}_(s) and the new current row is j+1. The counter of occurrences associated with row j+1 is set to 1.

Else, if r<u , the candidate parameter is rejected at step 987, that is w_(s)=w_(s−1), the current row is kept at j and the counter of occurrences associated with row j is incremented by one.

In both cases, the algorithm checks whether a stopping criterion is met, for example whether s=N_(s), that is whether a maximum number of samples has been reached or if the RRAM is full. In the negative, the algorithm goes back to step 920. Otherwise, it stops. According to a variant, instead of stopping when the RRAM is full, that is when the last row has been reached, the algorithm loops back to the first row and goes on as before. This variant is of interest when convergence to the posterior is slow.

Once the logistic regression classifier has been trained on the training dataset, that is, in practice, when the N_(s) samples of parameter vector have been stored in the RRAM, the RRAM can be used for the classification of new observation as shown in FIG. 10.

FIG. 10 shows a method for classifying new observation with a RRAM based logistic regression classifier after it has been trained by a training method according to the first embodiment of the invention.

The RRAM contains Ns samples of the model parameter vector w_(s), s=1, . . . , Ns. It is nevertheless important to understand that the same sample value may occur several times, the occurrences of the same sample value being stored in the same row. More specifically, if we denote v_(j) the integer stored in the counter of occurrences associated with row j and J the number of rows where a sample has been stored (i.e. the rows for which the associated counters are not equal to zero), we have the relationship:

$\begin{matrix} {N_{s} = {\sum\limits_{j = 1}^{J}\; v_{j}}} & (11) \end{matrix}$

At step 1000, when a new observation x_(new) is to be classified, its components are applied as data control signals to columns 1, . . . , M. These control signals are in practice voltages proportional to the components of x_(new).

The classifying then enters an iterative loop, the loop being iterated as long as an occurrence counter is not zero.

At step 1010, the first J rows are selected and output lines output[1], output[2], . . . , output[J] are read in parallel or in series by the processor. These output lines provide the dot products w_(j) ^(T)x_(new), j=1, . . . , J where w_(u) is stored at row j. According to a variant, the first B rows of the RRAM can be ignored or discarded, these first B rows corresponding to a burn-in period of the training phase, corresponding to convergence to the posterior. In such instance, the J rows would be following these B rows.

After the output lines have been read, all the counters of occurrences that are not equal to zero are decremented by one at step 1020.

It is the checked at 1030 whether ∃j∈{1, . . . , J} such as v_(j)>0. In the affirmative the algorithm goes back to step 1010.

Conversely, in the negative, the iterative loop is exited. The reading of the output lines provides the sequence of samples (of the parameter vector) w_(s), s=1, . . . , Ns.

Alternatively, instead of sequentially performing reading iterations until all the counters are equal to zero, the output of each line output[j] may be amplified by an amplifier whose gain is controlled by the value v_(j) stored in the corresponding counter.

The processor calculates at step 1040 an average logistic regression value over the samples, according to expression (6-1) or (6-2).

Finally, at step 1050, it is decided upon comparing P(T_(n)=1|x_(new)) or P(T_(n)=0|x_(new)) with a predetermined threshold value (e.g. ½) whether data element x_(new) belongs to the first class, 1051, or the second class, 1052.

FIG. 11 shows the structure of a resistive RAM which can be used for a training method according to a second embodiment of the invention.

The structure of this resistive RAM differs from the one used in the first embodiment by the fact that the parameter vectors of the models are stored as differential pairs. More precisely, each parameter vector w_(j) is represented by a pair (w_(j) ⁺, w_(j) ⁻) with w_(j)=w_(j) ⁺−w_(j) ⁻ where the first part, w_(j) ⁺, and the second part, w_(j) ⁻, of parameter vector w_(j) are generated and stored separately in the RRAM.

More specifically, the resistive RAM is comprised of word lines which are addressed by word select signals row[0], row[1], . . . , row[P]. Each word select signal, row[j] controls in fact two sub-rows: a first sub-row storing the first part of the parameter vector, w_(j) ⁺, and a second sub-row containing the second part of the parameter vector, w_(j) ⁻. The outputs of the cells of the first sub-row of row j are connected to a first sub-row output line, sub_output⁺[j] and the outputs of the cells of the second sub-row are connected to a second sub-row output line sub_output⁻[j]. The first and second sub-row output lines are connected to the inputs of a subtractor sub[j].

The first sub-row of row j stores w_(j) ⁺ and the second sub-row of row j stores w_(j) ⁻. Hence, when the components of a vector x are applied to the data control lines and row j is selected, the first sub-row output line outputs (w_(j) ⁺)^(T)x and the second sub-row output line outputs (w_(j) ⁻)^(T)x. The output of subtractor sub[j] is therefore (w_(j) ⁺)^(T)x−(w_(j) ⁻)^(T) x=w_(j) ^(T)x.

The last row of the RRAM can be dedicated to an RNG as in the first embodiment. Alternatively, the RNG can be located off the RRAM.

The RRAM of FIG. 11 can be used for training a logistic regression classifier along the same lines as those described in relation with FIG. 9. Basically, for generating a parameter vector of a model, the first part, w_(j) ⁺, and the second part, w_(j) ⁻, of the parameter vector are generated and respectively stored in the first sub-row and second sub-row of row j. However, a single counter of occurrences is associated to each row (and not each sub-row). Hence, when a new candidate vector, {tilde over (w)}_(s) is generated, it first part {tilde over (w)}_(s) ⁺ and its second part {tilde over (w)}_(s) ⁻ are respectively stored in the first sub-row and second sub-row of the next row, j+1. Otherwise, the counter of occurrences associated with the row j is incremented.

The first variant (programming with the SET operation) and the second variant (programming with the RESET operation) envisaged for the first embodiment equally apply to the second embodiment.

FIG. 12 schematically illustrates the programming of a RRAM in a binary regime.

A third embodiment of the present invention draws on a further way of programming a resistive memory, when it is in a so-called binary regime.

More specifically, when a RRAM cell is a high resistance state (HRS) and a programming voltage value V_(set) belonging to a given range is applied to this cell during a SET operation, the RRAM cell switches to a low resistance state (HRS) with a flipping probability p which depends upon voltage value V_(set).

The left part of FIG. 12 shows the probability of a RRAM cell to flip from HRS to LRS (SET probability) as a function of the SET voltage. The probability of flipping the state of a memory cell follows a Bernoulli distribution:

p(X=x)=p ^(x)(1−p)^(1−x)   (12)

where x=0 represents the HRS state and x=1 represents the LRS state.

Similarly, when a RRAM cell is a low resistance state (LRS) and a programming voltage value V_(reset) belonging to a given range is applied to this cell during a RESET operation, the RRAM cell switches to a high resistance state (HRS) with a flipping probability p′ which depends upon voltage value V_(reset).

According to a variant, the decision as to the whether the state of a RRAM cell is to be flipped can be generated by using a pseudo-random generator (e.g. a linear-feedback shift register or LFSR). The random number output by the pseudo-random generator is compared with a predetermined threshold value and the decision of flipping the state of a cell is made based upon the result of the comparison. For example, if the random number lies above the threshold value the state of the cell is flipped and, if not, the state of the cell is left unchanged. Alternatively, it can be generated by using a dedicated row of the RRAM, as already explained in relation with FIG. 8 for generating a random value according to a uniform law. In such a case, a voltage close to the threshold SET voltage is applied as data control signal to the columns while selecting said dedicated row. The random value read from the dedicated row of the RAM is then compared with a predetermined threshold value and, again, the decision of flipping the state of a cell is made upon the result of the comparison.

The method for training a logistic regression classifier according to the third embodiment also uses a resistive RAM structure as depicted in FIG. 8. It follows the same flowchart as in FIG. 9 except for steps 930 and 940.

Indeed, the candidate parameter vector, {tilde over (w)}_(s), is generated here from the current parameter vector, w_(s−1), by considering each bit thereof and:

-   -   if the bit read corresponds to a LRS state, flipping it with a         probability p;     -   if the bit read corresponds to a HRS state, flipping it with a         probability p′.

The probability p′ can be chosen such that p′=p.

Furthermore, the priors p(w_(s−1)) and p({tilde over (w)}_(s)) can be computed according to a Bernoulli law the parameters of which are obtained in a calibration phase.

Finally, the calculation of the likelihoods and of the acceptance ratio remains the same as in the first embodiment.

The man skilled in the art will understand that, instead of simulating a random walk according to a normal Markovian process, the training method according to the third embodiment simulates a discretized walk through the parameter space. In practice, when the number M of attributes is relatively high, the training method according to the third embodiment provides satisfactory results.

Once the RRAM has been trained according to the training method according to the third embodiment, it can be used as a logistic regression classifier as explained in relation of FIG. 10.

According to a variant, the logistic function in step 1040 can be omitted and the probability for a new observation, x_(new), to belong to a class can be directly obtained from the scores, namely for the first class:

$\begin{matrix} {{P\left( {T_{n} = \left. 1 \middle| x_{new} \right.} \right)} = {\frac{1}{Ns}{\sum\limits_{s = 1}^{Ns}{w_{s}^{T}x_{new}}}}} & (13) \end{matrix}$

The present invention has been described in the context of the training of a logistic regression classifier, which classifies data into a class C (first class) or its complementary C (second class), the class the data belongs to being identified by a binary target value. The man skilled in the art will nevertheless understand that the invention can be extended to the training of a classifier which classifies data into a plurality of independent classes C₁, C₂, . . . , C_(Q) or the respective complementary classes. The RRAM is then divided in Q areas, each area being dedicated to a class C, and being associated with a corresponding logistic regression classifier. Alternatively, Q RRAMs can be used, each RRAM being dedicated to a class C_(q) and being associated with a corresponding logistic regression classifier.

Finally, the training method according to the invention extends to a multinomial logistic classifier by using a softmax model instead of the logit model described above. 

1. A method for training a logistic regression classifier on a dataset, each element of the dataset being represented by a vector x of M attributes, hereinafter referred to as components, and being labelled with a binary target indicating whether the element belongs to a first class or a second class, the probability of an element x belonging to a class being modelled by a logistic function applied to a score w^(T)x of said element, where w is a parameter vector of size M representing the model, said method comprising the sampling of said parameter vector according to its posterior probability density with respect to the data set, said method comprising: providing a resistive RAM, each row of the resistive RAM comprising M cells which can be programmed in a first resistance state or a second resistance state, each row being intended to store a parameter vector, a counter of occurrences being associated with each row; initializing said resistive RAM by setting all cells in said first resistance state; reading an initial vector {tilde over (w)}₀ from the first row and entering an iterative loop comprising: (a) generating a candidate parameter vector, {tilde over (w)}_(s), from the current parameter vector, w_(s−1), by reading the cells of the current row and programming the resistances of the cells of the next row, the resistances of the cells of the next row being derived from the resistances of the cells of the current row according to a Markovian process; (b) computing an acceptance ratio, r, of the candidate parameter vector, {tilde over (w)}_(s), as the ratio of the posterior densities of {tilde over (w)}_(s) and w_(s−1), with respect to the dataset; (c) drawing a value u from a uniform distribution between 0 and 1 and comparing it with the acceptance ratio, r; (d1) if u r taking the next row as the current row and jumping to step (a); (d2) else, keeping the current row, incrementing the counter of occurrences associated therewith and jumping to step (a); the training method being stopped when a predetermined stopping criterion is met.
 2. The method for training a logistic regression classifier according to claim 1, wherein the first resistance state is a high resistance state and the second resistance state is a low resistance state, and that, at step (a), the current or voltage read from a cell of the current row is used for applying a voltage to a corresponding cell of the next row while programming said cell in the low resistance state.
 3. The method for training a logistic regression classifier according to claim 1, wherein the first resistance state is a low resistance state and the second resistance state is a high resistance state, and that, at step (a), the current or voltage read from a cell of the current row is amplified by an exponentiation circuit before being applied as a voltage to a corresponding cell of the next row while programming this cell in the high resistance state.
 4. The method for training a logistic regression classifier according to claim 3, wherein the value u from said uniform distribution is obtained by applying a predetermined voltage to all the cells of a dedicated row, the outputs of the dedicated row being connected to an output line, said predetermined voltage being chosen close to the threshold voltage for programming the cells in a high resistance state, the value u being obtained from the output of said output line.
 5. The method for training a logistic regression classifier according to claim 1, wherein at step (a) the resistances of the cells of the next row are programmed by switching the state of each of the resistances of the current row with a switching probability value.
 6. The method for training a logistic regression classifier according to claim 1, wherein the ratio of the posterior densities of {tilde over (w)}_(s) and w_(s−1) are obtained as the product of the ratio of the likelihoods $\frac{\left( {\overset{\sim}{w}}_{s} \right)}{\left( w_{s - 1} \right)}$ with respect to the dataset and the ratio of the priors $\frac{p\left( {\overset{\sim}{w}}_{s} \right)}{p\left( w_{s - 1} \right)}.$
 7. The method for training a logistic regression classifier according to claim 6, wherein the likelihood of the candidate parameter vector

({tilde over (w)}_(s)) is calculated as ${\left( {\overset{\sim}{w}}_{s} \right)} = {\prod\limits_{n = 1}^{N}{\left( \frac{1}{1 + {\exp \left( {{- {\overset{\sim}{w}}_{s}}x_{n}} \right)}} \right)^{t_{n}}\left( \frac{\exp \left( {{- {\overset{\sim}{w}}_{s}^{T}}x_{n}} \right)}{1 + {\exp \left( {{- {\overset{\sim}{w}}_{s}^{T}}x_{n}} \right)}} \right)^{1 - t_{n}}}}$ and the likelihood of the current parameter vector ${\left( w_{s - 1} \right)} = {\prod\limits_{n = 1}^{N}{\left( \frac{1}{1 + {\exp \left( {{- w_{s - 1}}x_{n}} \right)}} \right)^{t_{n}}\left( \frac{\exp \left( {{- w_{s - 1}^{T}}x_{n}} \right)}{1 + {\exp \left( {{- w_{s - 1}^{T}}x_{n}} \right)}} \right)^{1 - t_{n}}}}$ where x_(n), n=1, . . . , N are vectors representing data elements of the dataset, the dot product {tilde over (w)}_(s) ^(T)x_(n) being obtained by applying the components of vector x_(n) to the cells of the row containing candidate parameter vector {tilde over (w)}_(s), and by reading the common output line to which the cells of the row containing {tilde over (w)}_(s) are connected, the dot product w_(s−1) ^(T)x_(n) being obtained by applying the components of vector x_(n) to the cells of the row containing current parameter vector w_(s−1), and by reading the common output line to which the cells of the row containing w_(s−1) are connected.
 8. The method for training a logistic regression classifier according to claim 1, wherein the predetermined stopping criterion is met when a predetermined number of samples (Ns) is reached or when the resistive RAM is full.
 9. The method for classifying an observation with a logistic regression classifier trained according to claim 1, observation to be classified being represented by a vector x_(new) of M components, further comprising: respectively applying the M components to the M cells of each row of the resistive RAM storing a parameter vector; (a′) reading the output line associated with each row for which the counter of occurrences is not null, the reading of the output line providing the dot product w_(s) ^(T)x_(new) where w_(s) is the parameter vector stored at this row; (b′) decrementing the respective counters of occurrences of all the output lines that have been read at step (a′); steps (a′) and (b′) being repeated until all the counters of occurrences have reached zero, thereby obtaining a sequence of Ns parameter vectors, w_(s) ^(T)x_(new), s=1, . . . , Ns. computing the average ${P\left( {T_{n} = \left. 1 \middle| x_{new} \right.} \right)} = {\frac{1}{Ns}{\sum\limits_{s = 1}^{Ns}\frac{1}{1 + {\exp \left( {{- w_{s}^{T}}x_{new}} \right)}}}}$ and comparing it with a predetermined threshold value in order to determine whether said observation belongs to the first class of the second class.
 10. A method for training a logistic regression classifier on a dataset, each element of the dataset being represented by a vector x of M attributes and being labelled with a binary target indicating whether the element belongs to a first class or a second class, the probability of an element x belonging to a class being modelled by a logistic function applied to a score w^(T)x of said element, where w is a parameter vector of size M representing the model, said method comprising the sampling of said parameter vector according to its posterior probability density with respect to the dataset, said method comprising: providing a resistive RAM, each row of the resistive RAM comprising a first sub-row and a second sub-row , each sub-row comprising M cells which can be programmed in a first resistance state or a second resistance state, the first sub-row being configured to store a first part of a parameter vector, the second sub-row being configured to store a second part of the same parameter vector, this parameter vector being obtained as the difference between said first part and said second part, and a counter of occurrences being associated with each row; initializing said resistive RANI by setting all cells in said first resistance state; reading the first part and second part of an initial vector {tilde over (w)}₀ from the first row and entering an iterative loop comprising: (a) generating the first part and second part of a candidate parameter vector, {tilde over (w)}_(s), respectively from the first part and second part of current parameter vector, w_(s−1), by reading the cells of the first and second sub-row of current row and programming the resistances of the first and second sub-row of next row, the resistances of the cells of the first and second sub-row of next row being derived from the resistances of the cells of the first and second sub-row of current row according to a Markovian process; (b) calculating the candidate parameter vector as the difference between its first part and second part; calculating the current parameter vector as the difference between its first part and second part; computing an acceptance ratio, r , of the candidate parameter vector, {tilde over (w)}_(s), as the ratio of the posterior densities of {tilde over (w)}_(s) and w_(s−1), with respect to the dataset; (c) drawing a value u from a uniform distribution between 0 and 1 and comparing it with the acceptance ratio, r; (d1) if it r taking the next row as the current row and jumping to step (a); (d2) else, keeping the current row, incrementing the counter of occurrences associated therewith and jumping to step (a); the training method being stopped when a predetermined stopping criterion is met. 